HackerRank Stock Maximize
提出
11/12 test cases failed :(
code: python
import math
import os
import random
import re
import sys
#
# Complete the 'stockmax' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts INTEGER_ARRAY prices as parameter.
#
def stockmax(prices):
# Write your code here
money = 0
stock = 0
for i in range(len(prices)-1):
if (pricesi+1 > pricesi): stock += 1
else:
stock = 0
return money + stock*prices-1 if __name__ == '__main__':
t = int(input().strip())
for t_itr in range(t):
n = int(input().strip())
prices = list(map(int, input().rstrip().split()))
result = stockmax(prices)
fptr.write(str(result) + '\n')
fptr.close()
解答
code: python
import math
import os
import random
import re
import sys
#
# Complete the 'stockmax' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts INTEGER_ARRAY prices as parameter.
#
def stockmax(prices):
# Write your code here
for i, p in enumerate(reversed(prices)):
if i == 0:
continue
else:
else:
maxarr.append(p)
maxarr = list(reversed(maxarr))
ans = 0
for i in range(len(prices)):
return ans
if __name__ == '__main__':
t = int(input().strip())
for t_itr in range(t):
n = int(input().strip())
prices = list(map(int, input().rstrip().split()))
result = stockmax(prices)
fptr.write(str(result) + '\n')
fptr.close()
メモ